package com.cz.activemq;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;


@Slf4j
public class MessageSender {


    private static String url = "tcp://localhost:61616";
    private static String subject = "TEST.QUEUE";

    public static void main(String[] args) {
        try {
            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
            Connection connection = connectionFactory.createConnection();
            connection.start();

            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = session.createQueue(subject);
            MessageProducer producer = session.createProducer(destination);

            String text = "Hello from ActiveMQ!";
            TextMessage message = session.createTextMessage(text);
            producer.send(message);

            System.out.println("Sent message '" + text + "'");

            connection.close();
        } catch (JMSException e) {
            log.error(e.getMessage(),e);
        } finally {
        }
    }
}
